package com.bluesky.example.concurrent;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class WebServer {
	static int clientCount = 0;

	private static void startServerThread() {
		new Thread(new Runnable() {
			@Override
			public void run() {

				try {
					ServerSocket socket = new ServerSocket(80);
					while (true) {
						final Socket connection = socket.accept();
						clientCount++;

						new RequestWorkThread(connection, clientCount).start();

					}
				} catch (Exception e) {
				}
			}
		}).start();
	}

	public static void main(String[] args) throws IOException {
		startServerThread();

		for (int i = 0; i < 10; i++) {
			Thread t = new Thread(new WebClient("localhost"));
			t.start();

		}
	}

}
